home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / demos / cpitdemo / cpit_event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  6.7 KB  |  237 lines

  1. #ifndef lint
  2. static char SccsId[]= "@(#)cpit_event.c    V1.7    3/15/95";
  3. #endif
  4.  
  5. /*------------------------------------------------------------------
  6. | file name -- cpit_event.c
  7. |
  8. | functions             Description
  9. | ---------             -----------
  10. | InitSimpleEvents    Sets up service routines for simple event handling.
  11. | HandleEvents        Gathers and processes user inputs
  12. |
  13. | handle_pick_event    Service Function for pick events.
  14. | handle_window_event    Service Function for window events.
  15. | handle_quit_window    Quits the application or close the window.
  16. | check_hot_spots    Checks and handles commands contained in picked
  17. |                objects' names.
  18. |
  19. | ParseCommand        Analyzes the command contained in the chosen
  20. |                object's name.
  21. |
  22. |-----------------------------------------------------------------*/
  23.  
  24. /* This program can be linked to run:
  25. |
  26. |  With 100% CPU usage (which shows updates in a tight loop)
  27. |    comment #define DV_USE_TIMER
  28. |  With Time-Outs (which show update based on a timer.
  29. |    uncomment #define DV_USE_TIMER
  30. */
  31. #define DV_USE_TIMER 
  32.  
  33. #include "std.h"
  34. #include "dvstd.h"
  35. #include "dvtools.h"
  36. #include "dvGR.h"
  37. #include "VOstd.h"
  38. #include "Tfundecl.h"
  39. #include "dvinteract.h"
  40. #include "VOfundecl.h"
  41. #include "VUerfundecl.h"
  42. #include "VGfundecl.h"
  43. #include "cpit_vars.h"
  44. #include "cpit_fundecl.h"
  45.  
  46.  
  47.  
  48. /***************** Begin Function Declarations *************/
  49. LOCAL  void handle_pick_event V_P_((OBJECT location));
  50. LOCAL  void handle_quit_window V_P_((void));
  51. /***************** End Function Declarations *************/
  52.  
  53. /*-----------------------------------------------------------------
  54. |
  55. |  InitSimpleEvents()
  56. |       Performs the initialization needed for window events.
  57. |
  58. */
  59. void InitSimpleEvents 
  60. V_P_ ((void))
  61. {
  62.  
  63.   /* Setup the window events */
  64.   (VOID) VOscWinEventMask ((ULONG) (V_KEYPRESS | V_BUTTONPRESS |
  65.                                     V_KEYRELEASE | V_BUTTONRELEASE |
  66.                                     V_RESIZE | V_EXPOSE |
  67.                                     V_MOTIONNOTIFY |
  68.                                     V_WINDOW_QUIT),
  69.                            (ULONG) V_END_OF_LIST);
  70. }
  71.  
  72. /*-----------------------------------------------------------------
  73. |
  74. |  HandleEvents
  75. |       Gathers and processes user input.  Events are first processed
  76. |       by the event handler then checked on a case by case basis.
  77. */
  78. void HandleEvents 
  79. V_P_ ((void))
  80. {
  81.   OBJECT loc_event;
  82.  
  83.   /* See if there is an event to handle, only user input events
  84.   |  matching those set in VOscWinEventMask will be returned.
  85.   |
  86.   |  NOTE: VOloWinEventPoll will get the next event and then dispatch
  87.   |  non-DataViews events. Our posted AppTimeOut event to handle
  88.   |  dynamics, will be called as needeb by VOloWinEventPoll, which
  89.   |  calls XtAppNextEvent and XtDispatchEvent.
  90.   */
  91.  
  92. #ifdef DV_USE_TIMER
  93.  
  94.   loc_event = VOloWinEventPoll (V_WAIT);
  95.  
  96. #else  /* Not DV_USE_TIMER */
  97.  
  98.   /* Update the Display */
  99.   HandleDynamics();
  100.  
  101.   /* Get the Event */
  102.   loc_event = VOloWinEventPoll (V_NO_WAIT);
  103.  
  104. #endif /* DV_USE_TIMER */
  105.  
  106.  
  107.   /* If there is an event, handle it */
  108.   if (loc_event)
  109.     {
  110.       ActiveScreen = VOloScreen (loc_event);
  111.       (VOID) TscSetCurrentScreen (ActiveScreen);
  112.  
  113.       /* Let the event handler update input objects and...
  114.       |  PICK events: HandlPickEvent() will be called
  115.       |  WINDOW events: handle_window_event() will be called
  116.       */
  117.       (VOID) VUerHandleLocEvent (loc_event);
  118.  
  119.       /* Now Look for Events */
  120.       switch (VOloType (loc_event))
  121.         {
  122.         case V_RESIZE:
  123.           (VOID) TscReset (ActiveScreen);
  124.           break;
  125.         case V_EXPOSE:
  126.           (VOID) TscRedraw (ActiveScreen, (RECTANGLE *) NULL);
  127.           break;
  128.         case V_WINDOW_QUIT:
  129.           handle_quit_window ();
  130.           break;
  131.         case V_BUTTONPRESS:
  132.           handle_pick_event (loc_event);
  133.           break;
  134.         }
  135.     }
  136. }
  137.  
  138. /*-----------------------------------------------------------------
  139. |
  140. |  handle_pick_event
  141. |
  142. |       Checks to see if we've selected a named object. If we have
  143. |       it parses the command embedded in the name.
  144. |
  145. |       Only the first letter of the name is used for the command.
  146. |       The commands have the following meanings:
  147. |
  148. |
  149. |       NOTE:   The <varname> field will be used at a later date
  150. |               to control the dynamics in certain objects.  Currently
  151. |               you will find no routines that make use of this field.
  152. |
  153. |               Q*********         - Quits the application
  154. |
  155. |               G:<viewname>     - Goto viewname
  156. |               N:<varname>       - Starts a linked list of NEXT views.
  157. |               P:<varname>       - Display the PREVIOUS view.
  158. |
  159. |               O:<viewname>     - OVERLAYS the named view.
  160. |               D:<viewname>     - DELETES the overlayed named view.
  161. |
  162. */
  163. /* ARGSUSED */
  164. LOCAL void 
  165. handle_pick_event (location)
  166.      OBJECT location;
  167. {
  168.   CHAR *obj_name, *cmd;
  169.   DRAWPORT dp;
  170.   OBJECT obj, dr;
  171.  
  172.   /* Find the selected object */
  173.   dp = TloGetSelectedDrawport (location);
  174.   obj = TloGetSelectedObject (location);
  175.  
  176.   if (obj)
  177.     {
  178.       /* Get the object's name */
  179.       dr = TviGetDrawing (TdpGetView (dp));
  180.       obj_name = TdrGetObjectName (dr, obj);
  181.  
  182.       /* Handle the command associated with the object's name */
  183.       if (obj_name)
  184.         {
  185.           cmd = obj_name;
  186.  
  187.           /* Process the current command */
  188.           switch ((INT) cmd[0])
  189.             {
  190.               /* OVERLAY display (O) */
  191.             case OVERLAY_COMMAND:
  192.               OverlayDisplay (&cmd[2]); /* found in cpit_dsp.c */
  193.               break;
  194.  
  195.               /* RESET Display (G) */
  196.             case GOTO_COMMAND:
  197.               SwitchDisplay (RESET_DISPLAY, &cmd[2]);   /* found in cpit_dsp.c */
  198.               break;
  199.  
  200.               /* NEXT Display (G) */
  201.             case NEXT_COMMAND:
  202.               SwitchDisplay (NEXT_DISPLAY, &cmd[2]);    /* found in cpit_dsp.c */
  203.               break;
  204.  
  205.               /* PREVIOUS display (P) */
  206.             case PREVIOUS_COMMAND:
  207.               SwitchDisplay (PREV_DISPLAY, (CHAR *) NULL);      /* found in cpit_dsp.c */
  208.               break;
  209.  
  210.               /* DELETE command (D) */
  211.             case DELETE_COMMAND:
  212.               RemoveDisplay (&cmd[2]);  /* found in cpit_dsp.c */
  213.               break;
  214.  
  215.               /* QUIT the application */
  216.             case QUIT_COMMAND:
  217.               handle_quit_window ();
  218.               break;
  219.  
  220.             default:
  221.               break;
  222.             }
  223.         }
  224.     }
  225. }
  226.  
  227. /*-----------------------------------------------------------------
  228. |
  229. |  handle_quit_window
  230. |    Sets the quit flag to stop the program.
  231. */
  232. LOCAL void handle_quit_window 
  233. V_P_ ((void))
  234. {
  235.   ApplicationState = (DV_BOOL) NOT_RUNNING;
  236. }
  237.